package my.study.org.springframework.aop.examples.example1;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;
import org.apache.commons.lang.builder.ToStringBuilder;

/**
 * Audience的周围通知
 * @author fanhongjie
 *
 */
public class AudienceAroundAdvice implements MethodInterceptor {
	private Audience audience;
	
	public Object invoke(MethodInvocation methodInvocation) throws Throwable {
		try {
			this.audience.takeSeats();
			this.audience.turnOffCellPhones();
			Object returValue = methodInvocation.proceed();
			this.audience.applaud();
			return returValue;
		} catch (Exception e) {
			this.audience.demandRefund();
			throw e;
		}
	}

	public Audience getAudience() {
		return audience;
	}

	public void setAudience(Audience audience) {
		this.audience = audience;
	}
}
